﻿// a particle effect that emulates coin
coinEmitter = gamvas.ParticleEmitter.extend({
    // overwrite constructor
    create: function (name, x, y, img, anim) {
        // position our emitter slightly over the screen
        var dim = gamvas.getCanvasDimension();
        this._super(name, 0, -dim.h * 0.5 - 20, img, anim);
        var st = gamvas.state.getCurrentState();

        // get our coin image and set its center to the bottom center
        var coinimg = new gamvas.Image(st.resource.getImage(baseURL + 'Content/images/coin.png'));
        coinimg.setCenter(1, 30);
        this.setImage(coinimg);

        // our coindrops orient themself along their path
        this.aligntoPath = true;

        // start with 100 drops per second
        this.setParticleRate(10);

        // let the particles start from a area slightly wider then the screen
        // range is always +/- from the center, so we use 0.6 time screen width
        this.setParticleStartPositionRange(new gamvas.Vector2D(dim.w * 0.6, 0));

        // set the alpha of our coindrops to 0.5 over whole lifetime
        //this.setAlphaTable([[0.0, 0.5], [1.0, 0.5]]);

        // coindrops do fall fast
        this.setParticleSpeed(dim.h / 4);
        this.setParticleSpeedRange(dim.h * 0.1);

        // the lifetime is something you have to match to your speed and
        // speed range by try and error, so they and up over the water
        this.setParticleLifeTime(5);
        //this.setParticleLifeTimeRange(0.06);

        // emulate a bit of wind by turning the emitter slightly
        //this.setRotation(0.15);
    },

    draw: function (t) {
        // call the super draing function to get the actual
        // particles drawn
        this._super(t);
    },

    onParticleEnd: function (pos, rot, scale, vel) {
    }
});
